package com.xx.controller.util;

import com.xx.springBootUtil.util.ObjectHelper;
import com.xx.springBootUtil.zzcache.ZZCacheUtils;
import com.xx.util.util.JsonUtils;
import com.xx.xunyou.entity.user.vo.LoginVo;

/**
 * @program: xunyou-parent
 * @author: zhl
 * @create: 2019-05-19
 **/

public class MyCachUtil {

    /**
     * 获取登录信息
     * @param token
     * @return
     */
    public static LoginVo getLoginVoByToken(String token){
        String s = ZZCacheUtils.get(token);
        if (ObjectHelper.isNotEmpty(s)){
            LoginVo loginVo = JsonUtils.jsonToPojo(s, LoginVo.class);
            return loginVo;
        }
        return null;
    }

    /**
     * 根据token获取userId
     */
    public static Integer getUserIdByToken(String token){

        if (ObjectHelper.isNotEmpty(token)){
            Integer userId = null;
            LoginVo loginVoByToken = MyCachUtil.getLoginVoByToken(token);
            if (ObjectHelper.isNotEmpty(loginVoByToken)){
                userId = loginVoByToken.getId();
            }
            return userId;
        }
        return null;
    }

}
